#include "LoadedImage.h"
#include "include/PowerLibraryEngine.h"

CLoadedImage::CLoadedImage()
{
}

CLoadedImage::~CLoadedImage()
{
}

CColor CLoadedImage::GetPixel(u32 x,u32 y)
{
	u32 Pixel = Data[y*GetW()+x];
	u8 PixelR = (u8)(Pixel << 3);
	u8 PixelG = (u8)(Pixel << 2);
	u8 PixelB = (u8)(Pixel << 1);
	u8 PixelA = (u8)(Pixel);

	CColor Temp((vPos)((vPos)(PixelR))/(vPos)(255.0),(vPos)((vPos)(PixelG))/(vPos)(255.0),(vPos)((vPos)(PixelB))/(vPos)(255.0),(vPos)((vPos)(PixelA))/(vPos)(255.0));
	return Temp;
}

IImage *CLoadedImage::Clone()
{
    CLoadedImage *Temp = new CLoadedImage();
    Temp->w = w;
    Temp->h = h;
    Temp->CopyPixelsFrom(Data);

    return Temp;

}

void CLoadedImage::CopyPixelsFrom(u32 *Where)
{
	if (Data)
	{
		DEALLOCATEARRAY(Data);
	}

	Data = new u32[w*h];
	memcpy(Data,Where,sizeof(u32)*w*h);
}
